package com.niiwoo.civet.mobile.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.niiwoo.civet.account.constant.AccountRegisterErrorCode;
import com.niiwoo.civet.account.dto.common.LanMaoGatewayRequestDTO;
import com.niiwoo.civet.account.dto.request.AccountRegisterStatusRequestDTO;
import com.niiwoo.civet.account.dto.request.CreateRegisterOrderRequestDTO;
import com.niiwoo.civet.account.dto.request.OpenCompanyAccountRequestDTO;
import com.niiwoo.civet.account.dto.response.AccountRegisterStatusResponseDTO;
import com.niiwoo.civet.account.enums.OpenAccountMajorWay;
import com.niiwoo.civet.account.enums.OpenAccountWayEnum;
import com.niiwoo.civet.account.service.AccountRegisterDubboService;
import com.niiwoo.civet.base.constant.OrgConstant;
import com.niiwoo.civet.mobile.util.ParameterValidator;
import com.niiwoo.civet.mobile.util.R360RedisService;
import com.niiwoo.civet.mobile.vo.request.*;
import com.niiwoo.civet.mobile.vo.response.AccountRegisterPrepareResponseVO;
import com.niiwoo.civet.mobile.vo.response.AccountRegisterStatusResponseVO;
import com.niiwoo.civet.mobile.vo.response.CompanyAccountRegisterPrepareResponseVO;
import com.niiwoo.civet.user.constants.LoginAccountErrorCode;
import com.niiwoo.civet.user.dto.request.OrganizationInfoReqDTO;
import com.niiwoo.civet.user.dto.request.OrganizationRequestDTO;
import com.niiwoo.civet.user.dto.response.OrganizationInfoRespDTO;
import com.niiwoo.civet.user.dto.response.UserIdentityInfoResponseDTO;
import com.niiwoo.civet.user.enums.UserDataStatusEnum;
import com.niiwoo.civet.user.enums.UserDataTypeEnum;
import com.niiwoo.civet.user.service.OrganizationDubboService;
import com.niiwoo.civet.user.service.UserIdentityDubboService;
import com.niiwoo.civet.user.service.UserStatusDubboService;
import com.niiwoo.tripod.base.component.PrivacyMasks;
import com.niiwoo.tripod.lanmao.enums.UserRoleEnum;
import com.niiwoo.tripod.provider.exception.BizException;
import com.niiwoo.tripod.web.annotation.AuthIgnore;
import com.niiwoo.tripod.web.util.PrincipalContext;
import com.niiwoo.tripod.web.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.LocalDateTime;
import org.joda.time.Years;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.*;

/**
 * 开户
 */
@RestController
@RequestMapping("/account/register")
@Api(tags = "个人开户(李健)", description = "/account/register")
@Slf4j
public class AccountRegisterController {

    private static final List<UserRoleEnum> SUPPORT_ROLE_LIST = Arrays.asList(UserRoleEnum.BORROWERS, UserRoleEnum.INVESTOR);

    private static final List<UserRoleEnum> R360_SUPPORT_ROLE_LIST = Collections.singletonList(UserRoleEnum.BORROWERS);

    @Reference(version = "1.0.0")
    AccountRegisterDubboService accountRegisterService;

    @Reference(version = "1.0.0")
    UserIdentityDubboService userIdentityService;

    @Reference(version = "1.0.0")
    UserStatusDubboService userStatusDubboService;

    @Reference(version = "1.0.0")
    OrganizationDubboService organizationDubboService;

    @Autowired
    RedisTemplate<String, String> redisTemplate;

    @Autowired
    R360RedisService r360RedisService;

    @Autowired
    PrivacyMasks privacyMasks;

    @PostMapping("/status/h5")
    @ApiOperation("开户前状态检查")
    @AuthIgnore
    public Result<AccountRegisterStatusResponseVO> h5StatusCheck(@RequestBody @Valid AccountRegisterStatusRequestVO requestVO) {
        log.info("开户前状态检查,token={},渠道={},请求参数={}",requestVO.getToken(),requestVO.getChannel(), JSONObject.toJSONString(requestVO));
        return doStatusCheck(requestVO, this.verifyTokenAndGetUserId(requestVO.getToken(), requestVO.getChannel()), R360_SUPPORT_ROLE_LIST);
    }

    @PostMapping("/status")
    @ApiOperation("开户前状态检查")
    public Result<AccountRegisterStatusResponseVO> statusCheck(@RequestBody @Valid AccountRegisterStatusRequestVO requestVO) {
        log.info("开户前状态检查,token={},渠道={},请求参数={}",requestVO.getToken(),requestVO.getChannel(), JSONObject.toJSONString(requestVO));
        return doStatusCheck(requestVO, getUserId(), SUPPORT_ROLE_LIST);
    }

    private Result<AccountRegisterStatusResponseVO> doStatusCheck(AccountRegisterStatusRequestVO requestVO, String userId, List<UserRoleEnum> supportList) {
        AccountRegisterStatusResponseVO vo = new AccountRegisterStatusResponseVO();

        UserRoleEnum accountRole = getValidRole(requestVO.getAccountRole(), supportList);
        AccountRegisterStatusRequestDTO requestDTO = new AccountRegisterStatusRequestDTO();
        requestDTO.setUserId(userId);
        requestDTO.setAccountRole(accountRole);

        // 第三方渠道为机构极速借
        if(Objects.equals(R360RedisService.ThirdPart.ORG.getChannel(), requestVO.getChannel())) {
            // 机构极速借
            requestDTO.setOrgId(organizationDubboService.loadValidOrgId(requestVO.getOrgCode()));
            vo.setOpenAccountSource((byte)2);
        }else {
            vo.setOpenAccountSource((byte)1);
            requestDTO.setOrgId(OrgConstant.NIIWOO_ORG_ID);
        }

        AccountRegisterStatusResponseDTO responseDTO = accountRegisterService.verifyStatus(requestDTO);
        vo.setOpenAccountWay(responseDTO.getOpenAccountWay().getValue());
        vo.setAccountRole(requestVO.getAccountRole());

        log.info("开户前状态检查,token={},渠道={},响应结果={}",requestVO.getToken(),requestVO.getChannel(), JSONObject.toJSONString(vo));
        return Result.with(vo);
    }



    @PostMapping("/activate/prepare/h5")
    @ApiOperation("账户激活预处理h5")
    @AuthIgnore
    public Result<AccountRegisterPrepareResponseVO> h5ActivateAccount(@RequestBody @Valid AccountActivatePrepareRequestVO request) {
        log.info("账户激活预处理,token={},渠道={},请求参数={}",request.getToken(),request.getChannel(), JSONObject.toJSONString(request));
        return doPrepareAccountActivate(request, this.verifyTokenAndGetUserId(request.getToken(), request.getChannel()), this.getOpenAccountWay(OpenAccountMajorWay.ACTIVATE, request.getChannel()), R360_SUPPORT_ROLE_LIST);
    }

    @PostMapping("/activate/prepare")
    @ApiOperation("账户激活预处理")
    public Result<AccountRegisterPrepareResponseVO> activateAccount(@RequestBody @Valid AccountActivatePrepareRequestVO request) {
        request.setRedirectUrl(null);
        log.info("账户激活预处理,token={},渠道={},请求参数={}",request.getToken(),request.getChannel(), JSONObject.toJSONString(request));
        return doPrepareAccountActivate(request, getUserId(), OpenAccountWayEnum.ACTIVATE, SUPPORT_ROLE_LIST);
    }

    private Result<AccountRegisterPrepareResponseVO> doPrepareAccountActivate(AccountActivatePrepareRequestVO request, String userId, OpenAccountWayEnum openAccountWay, List<UserRoleEnum> supportList) {
        return prepareOpenAccount(() -> {
            CreateRegisterOrderRequestDTO createOrderRequestDto = new CreateRegisterOrderRequestDTO();
            createOrderRequestDto.setUserId(userId);
            createOrderRequestDto.setAccountRole(getValidRole(request.getAccountRole(), supportList));
            createOrderRequestDto.setRedirectUrl(request.getRedirectUrl());
            createOrderRequestDto.setOpenAccountWay(openAccountWay);
            createOrderRequestDto.setOrgId(OrgConstant.NIIWOO_ORG_ID);

            LanMaoGatewayRequestDTO lanMaoGatewayRequestDTO=accountRegisterService.createAccountActivateOrder(createOrderRequestDto);
            log.info("账户激活预处理,token={},渠道={},响应结果={}",request.getToken(),request.getChannel(), JSONObject.toJSONString(lanMaoGatewayRequestDTO));
            return lanMaoGatewayRequestDTO;
        });
    }

    @PostMapping("/person/prepare/h5")
    @ApiOperation("个人开户预处理")
    @AuthIgnore
    public Result<AccountRegisterPrepareResponseVO> h5PreparePersonAccount(@RequestBody @Valid AccountRegisterPrepareRequestVO request) {
        request.setBankCardNo(request.getBankCardNo().replaceAll("\\s", ""));

        log.info("个人开户预处理,姓名={},渠道={},机构编码={},请求参数={}",request.getName(),request.getChannel(),request.getOrgCode(),JSONObject.toJSONString(request));
        return doPreparePersonAccount(request, this.verifyTokenAndGetUserId(request.getToken(), request.getChannel()), this.getOpenAccountWay(OpenAccountMajorWay.PERSON_BIND_BANK_CARD_REGISTER, request.getChannel()), R360_SUPPORT_ROLE_LIST);
    }

    @PostMapping("/company/prepare")
    @ApiOperation("企业开户预处理")
    @AuthIgnore
    public Result<CompanyAccountRegisterPrepareResponseVO> prepareCompanyAccount(@RequestBody @Valid CompanyAccountRegisterPrepareRequestVO requestVO) {
        OpenCompanyAccountRequestDTO openCompanyAccountRequestDTO=new OpenCompanyAccountRequestDTO();
        openCompanyAccountRequestDTO.setOrgId(requestVO.getOrgId());
        openCompanyAccountRequestDTO.setBorrowOrgId(requestVO.getBorrowOrgId());
        openCompanyAccountRequestDTO.setEnterpriseName(requestVO.getEnterpriseName());
        openCompanyAccountRequestDTO.setBankLicense(requestVO.getBankLicense());
        openCompanyAccountRequestDTO.setOrgNo(requestVO.getOrgNo());
        openCompanyAccountRequestDTO.setBusinessLicense(requestVO.getBusinessLicense());
        openCompanyAccountRequestDTO.setTaxNo(requestVO.getTaxNo());
        openCompanyAccountRequestDTO.setUnifiedCode(requestVO.getUnifiedCode());
        openCompanyAccountRequestDTO.setCreditCode(requestVO.getCreditCode());
        openCompanyAccountRequestDTO.setLegal(requestVO.getLegal());
        openCompanyAccountRequestDTO.setIdCardType(requestVO.getIdCardType());
        openCompanyAccountRequestDTO.setLegalIdCardNo(requestVO.getLegalIdCardNo());
        openCompanyAccountRequestDTO.setContact(requestVO.getContact());
        openCompanyAccountRequestDTO.setContactPhone(requestVO.getContactPhone());
        openCompanyAccountRequestDTO.setBankcardNo(requestVO.getBankcardNo());
        openCompanyAccountRequestDTO.setBankcode(requestVO.getBankcode());
        openCompanyAccountRequestDTO.setRedirectUrl(requestVO.getRedirectUrl());
        openCompanyAccountRequestDTO.setOpenAccountWay(requestVO.getOpenAccountWay());

        LanMaoGatewayRequestDTO lanMaoGatewayRequestDTO=accountRegisterService.createOpenCompanyAccountOrder(openCompanyAccountRequestDTO);

        CompanyAccountRegisterPrepareResponseVO companyAccountRegisterPrepareResponseVO=new CompanyAccountRegisterPrepareResponseVO();
        companyAccountRegisterPrepareResponseVO.setAction(lanMaoGatewayRequestDTO.getAction());
        companyAccountRegisterPrepareResponseVO.setParams(lanMaoGatewayRequestDTO.getParams());

        return Result.with(companyAccountRegisterPrepareResponseVO);
    }

    @PostMapping("/company/prepareAndSave")
    @ApiOperation("企业开户预处理与资料保存")
    @AuthIgnore
    public Result<CompanyAccountRegisterPrepareResponseVO> prepareCompanyAccount(@RequestBody @Valid CompanyAccountRegisterPrepareAndSaveRequestVO requestVO) {
        log.info("企业开户预处理与资料保存,机构ID={},请求参数={}", requestVO == null ? null : requestVO.getOrgId(), JSON.toJSONString(requestVO));
        OrganizationRequestDTO organizationRequestDTO=new OrganizationRequestDTO();
        organizationRequestDTO.setId(requestVO.getOrgId());
        organizationRequestDTO.setOrganizationName(requestVO.getEnterpriseName());
        organizationRequestDTO.setAccountOpeningBankLicense(requestVO.getBankLicense());
        organizationRequestDTO.setOrgNo(requestVO.getOrgNo());
        organizationRequestDTO.setCharterCode(requestVO.getBusinessLicense());
        organizationRequestDTO.setTaxId(requestVO.getTaxNo());
        organizationRequestDTO.setUnifiedSocialCreditCode(requestVO.getUnifiedCode());
        organizationRequestDTO.setInstitutionalReditCode(requestVO.getCreditCode());
        organizationRequestDTO.setRepresentative(requestVO.getLegal());
        organizationRequestDTO.setLegalPersonPhoneNumber(privacyMasks.encryptPrivacy(requestVO.getLegalPhone()));
        organizationRequestDTO.setEmail(requestVO.getEmail());
        organizationRequestDTO.setLegalPersonCertNumber(requestVO.getLegalIdCardNo());
        organizationRequestDTO.setCorporateContactsName(requestVO.getContact());
        organizationRequestDTO.setContactsPhoneName(requestVO.getContactPhone());
        organizationRequestDTO.setBankCode(requestVO.getBankcode());
        organizationRequestDTO.setOrgPublicAccount(privacyMasks.encryptPrivacy(requestVO.getBankcardNo()));

        organizationDubboService.updateUserOrgInfo(organizationRequestDTO);

        OpenCompanyAccountRequestDTO openCompanyAccountRequestDTO=new OpenCompanyAccountRequestDTO();
        openCompanyAccountRequestDTO.setOrgId(requestVO.getOrgId());
        openCompanyAccountRequestDTO.setBorrowOrgId(requestVO.getOrgId());
        openCompanyAccountRequestDTO.setEnterpriseName(requestVO.getEnterpriseName());
        openCompanyAccountRequestDTO.setBankLicense(requestVO.getBankLicense());
        openCompanyAccountRequestDTO.setOrgNo(requestVO.getOrgNo());
        openCompanyAccountRequestDTO.setBusinessLicense(requestVO.getBusinessLicense());
        openCompanyAccountRequestDTO.setTaxNo(requestVO.getTaxNo());
        openCompanyAccountRequestDTO.setUnifiedCode(requestVO.getUnifiedCode());
        openCompanyAccountRequestDTO.setCreditCode(requestVO.getCreditCode());
        openCompanyAccountRequestDTO.setLegal(requestVO.getLegal());
        openCompanyAccountRequestDTO.setIdCardType(requestVO.getIdCardType());
        openCompanyAccountRequestDTO.setLegalIdCardNo(requestVO.getLegalIdCardNo());
        openCompanyAccountRequestDTO.setContact(requestVO.getContact());
        openCompanyAccountRequestDTO.setContactPhone(requestVO.getContactPhone());
        openCompanyAccountRequestDTO.setBankcardNo(requestVO.getBankcardNo());
        openCompanyAccountRequestDTO.setBankcode(requestVO.getBankcode());
        openCompanyAccountRequestDTO.setRedirectUrl(requestVO.getRedirectUrl());
        openCompanyAccountRequestDTO.setOpenAccountWay(requestVO.getOpenAccountWay());

        LanMaoGatewayRequestDTO lanMaoGatewayRequestDTO=accountRegisterService.createOpenCompanyAccountOrder(openCompanyAccountRequestDTO);

        CompanyAccountRegisterPrepareResponseVO companyAccountRegisterPrepareResponseVO=new CompanyAccountRegisterPrepareResponseVO();
        companyAccountRegisterPrepareResponseVO.setAction(lanMaoGatewayRequestDTO.getAction());
        companyAccountRegisterPrepareResponseVO.setParams(lanMaoGatewayRequestDTO.getParams());

        return Result.with(companyAccountRegisterPrepareResponseVO);
    }

    @PostMapping("/person/prepare")
    @ApiOperation("个人开户预处理")
    public Result<AccountRegisterPrepareResponseVO> preparePersonAccount(@RequestBody @Valid AccountRegisterPrepareRequestVO request) {
        log.info("个人开户预处理,姓名={},渠道={},请求参数={}",request.getName(),request.getChannel(), JSONObject.toJSONString(request));
        return doPreparePersonAccount(request, getUserId(), OpenAccountWayEnum.PERSON_BIND_BANK_CARD_REGISTER, SUPPORT_ROLE_LIST);
    }

    private Result<AccountRegisterPrepareResponseVO> doPreparePersonAccount(AccountRegisterPrepareRequestVO request, String userId, OpenAccountWayEnum openAccountWay, List<UserRoleEnum> supportList) {
        return prepareOpenAccount(() -> {
            if (!ParameterValidator.isChineseName(request.getName())) {
                throw new BizException(LoginAccountErrorCode.NAME_FORMAT_ERROR);
            }
            //  校验身份证号是否大于等于18岁
            String card = request.getIdCardNo();

            LocalDateTime birthday = new LocalDateTime(Integer.valueOf(card.substring(6, 10)), Integer.valueOf(card.substring(10, 12)), Integer.valueOf(card.substring(12, 14)), 0, 0,0);
            LocalDateTime now = new LocalDateTime();
            if (birthday.isBefore(now) && Years.yearsBetween(birthday, now).getYears() < 18) {
                throw new BizException(AccountRegisterErrorCode.NO_ADULT_YET);
            }
            // 身份是否被使用
            if (userIdentityService.hasOtherIdentityMapping(userId, request.getIdCardNo())) {
                throw new BizException(AccountRegisterErrorCode.ID_HAS_BEEN_REGISTERED);
            }
            Optional.ofNullable(userStatusDubboService.getByUserIdAndType(userId, UserDataTypeEnum.TWO_ELEMENT))
                    .filter(s -> s.getDataStatus().equals(UserDataStatusEnum.RealNameAuthStatus.PASS_CERTIFIED.getStatus()))
                    .ifPresent(d -> {
                        // 二要素已认证则校验姓名和身份证号码, 比较请求参数和身份信息, 不正确则抛出异常
                        if (!isMatchNameAndIdCard(userIdentityService.get(getUserId()), request)) {
                            throw new BizException(AccountRegisterErrorCode.NOT_MATCH_NAME_AND_ID_CARD);
                        }
                    });
            CreateRegisterOrderRequestDTO createOrderRequestDto = new CreateRegisterOrderRequestDTO();
            createOrderRequestDto.setUserId(userId);
            createOrderRequestDto.setName(request.getName());
            createOrderRequestDto.setIdCardNo(request.getIdCardNo().toUpperCase());
            createOrderRequestDto.setBankCardNo(request.getBankCardNo());
            createOrderRequestDto.setBankCardMobileNo(request.getBankCardMobileNo());
            createOrderRequestDto.setAccountRole(getValidRole(request.getAccountRole(), supportList));
            createOrderRequestDto.setRedirectUrl(request.getRedirectUrl());
            createOrderRequestDto.setOpenAccountWay(openAccountWay);

            // 第三方渠道为机构极速借
            if(Objects.equals(R360RedisService.ThirdPart.ORG.getChannel(), request.getChannel())) {
                createOrderRequestDto.setOrgId(organizationDubboService.loadValidOrgId(request.getOrgCode()));
            }else{
                createOrderRequestDto.setOrgId(OrgConstant.NIIWOO_ORG_ID);
            }

            LanMaoGatewayRequestDTO lanMaoGatewayRequestDTO=accountRegisterService.createPersonalBindBankCardRegisterOrder(createOrderRequestDto);
            log.info("个人开户预处理,姓名={},渠道={},机构编码={},响应结果={}",request.getName(),request.getChannel(),request.getOrgCode(),JSONObject.toJSONString(lanMaoGatewayRequestDTO));
            return lanMaoGatewayRequestDTO;
        });
    }

    @PostMapping("/groupRelevance/prepare/h5")
    @ApiOperation("集团账户关联预处理")
    @AuthIgnore
    public Result<AccountRegisterPrepareResponseVO> h5PrepareGroupAccountRelevance(@RequestBody @Valid GroupAccountRegisterPrepareRequestVO request) {
        log.info("集团账户关联预处理,token={},渠道={},请求参数={}",request.getToken(),request.getChannel(),JSONObject.toJSONString(request));
        return doPrepareGroupAccountRelevance(request, this.verifyTokenAndGetUserId(request.getToken(), request.getChannel()), this.getOpenAccountWay(OpenAccountMajorWay.GROUP_ACCOUNT_CORRELATE, request.getChannel()), R360_SUPPORT_ROLE_LIST);
    }

    @PostMapping("/groupRelevance/prepare")
    @ApiOperation("集团账户关联预处理")
    public Result<AccountRegisterPrepareResponseVO> prepareGroupAccountRelevance(@RequestBody @Valid GroupAccountRegisterPrepareRequestVO request) {
        log.info("集团账户关联预处理,token={},渠道={},请求参数={}",request.getToken(),request.getChannel(),JSONObject.toJSONString(request));
        return doPrepareGroupAccountRelevance(request, getUserId(), OpenAccountWayEnum.GROUP_ACCOUNT_CORRELATE, SUPPORT_ROLE_LIST);
    }

    private Result<AccountRegisterPrepareResponseVO> doPrepareGroupAccountRelevance(GroupAccountRegisterPrepareRequestVO request, String userId, OpenAccountWayEnum openAccountWay, List<UserRoleEnum> supportList) {
        return prepareOpenAccount(() -> {
            CreateRegisterOrderRequestDTO createOrderRequestDto = new CreateRegisterOrderRequestDTO();
            createOrderRequestDto.setUserId(userId);
            createOrderRequestDto.setAccountRole(getValidRole(request.getAccountRole(), supportList));
            createOrderRequestDto.setRedirectUrl(request.getRedirectUrl());
            createOrderRequestDto.setOpenAccountWay(openAccountWay);
            createOrderRequestDto.setOrgId(OrgConstant.NIIWOO_ORG_ID);

            LanMaoGatewayRequestDTO lanMaoGatewayRequestDTO=accountRegisterService.createGroupAccountCorrelateOrder(createOrderRequestDto);
            log.info("集团账户关联预处理,token={},渠道={},响应结果={}",request.getToken(),request.getChannel(),JSONObject.toJSONString(lanMaoGatewayRequestDTO));
            return lanMaoGatewayRequestDTO;
        });
    }


    private UserRoleEnum getValidRole(Byte roleValue, List<UserRoleEnum> supportList) {
        UserRoleEnum roleEnum = UserRoleEnum.enumOf(roleValue);
        if (roleEnum == null || !supportList.contains(roleEnum)) {
            throw new BizException(AccountRegisterErrorCode.NOT_SUPPORT_ROLE);
        }
        return roleEnum;
    }

    /**
     * 开户预处理
     */
    private Result<AccountRegisterPrepareResponseVO> prepareOpenAccount(Prepare prepare) {
        // 创建开户订单
        LanMaoGatewayRequestDTO gatewayDTO = prepare.doCreateOrder();
        // 返回网关请求地址和参数
        AccountRegisterPrepareResponseVO prepareResponseVO = new AccountRegisterPrepareResponseVO();
        prepareResponseVO.setAction(gatewayDTO.getAction());
        prepareResponseVO.setParams(gatewayDTO.getParams());
        return Result.with(prepareResponseVO);
    }

    private boolean isMatchNameAndIdCard(UserIdentityInfoResponseDTO dto, AccountRegisterPrepareRequestVO vo) {
        if (dto == null) {
            return true;
        }
        if (StringUtils.isNotBlank(dto.getName()) && !vo.getName().equals(dto.getName())) {
            return false;
        }
        if (StringUtils.isNotBlank(dto.getIdCard()) && !vo.getIdCardNo().equals(dto.getIdCard())) {
            return false;
        }
        return true;
    }

    /**
     * 获取用户id
     */
    private String getUserId() {
        return String.valueOf(PrincipalContext.getUserId());
    }

    private String verifyTokenAndGetUserId(String token, Integer channel) {
        return channel == null ? r360RedisService.verifyTokenAndGetUserId(token) : r360RedisService.verifyTokenAndGetUserId(token, channel);
    }

    private OpenAccountWayEnum getOpenAccountWay(OpenAccountMajorWay majorWay, Integer channel) {
        return r360RedisService.getOpenAccountWayByChannel(majorWay, channel);
    }

    @FunctionalInterface
    private interface Prepare {

        LanMaoGatewayRequestDTO doCreateOrder();

    }

}
